/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.to.aboomy.bannersample.indicator.magicindicator;

import ohos.agp.database.DataSetPublisher;
import ohos.agp.database.DataSetSubscriber;
import ohos.app.Context;

/**
 * CommonNavigator适配器，通过它可轻松切换不同的指示器样式
 *
 * @since 2020-09-29
 */
public abstract class CommonNavigatorAdapter {
    private final DataSetPublisher mDataSetObservable = new DataSetPublisher();

    /**
     * 长度
     *
     * @return int
     */
    public abstract int getCount();

    /**
     * 获取IpagerTitleView
     *
     * @param context context
     * @param index index
     * @return IpagerTitleView
     */
    public abstract IpagerTitleView getTitleView(Context context, int index);

    /**
     * getIndicator
     *
     * @param context context
     * @return IpagerIndicator
     */
    public abstract IpagerIndicator getIndicator(Context context);

    /**
     * getTitleWeight
     *
     * @param context context
     * @param index index
     * @return float
     */
    public float getTitleWeight(Context context, int index) {
        return 1;
    }

    /**
     * registerDataSetObserver
     *
     * @param observer DataSetSubscriber
     */
    public final void registerDataSetObserver(DataSetSubscriber observer) {
        mDataSetObservable.registerSubscriber(observer);
    }

    /**
     * unregisterDataSetObserver
     *
     * @param observer DataSetSubscriber
     */
    public final void unregisterDataSetObserver(DataSetSubscriber observer) {
        mDataSetObservable.unregisterSubscriber(observer);
    }

    /**
     * notifyDataSetChanged
     */
    public final void notifyDataSetChanged() {
        mDataSetObservable.notifyChanged();
    }

    /**
     * 刷新
     */
    public final void notifyDataSetInvalidated() {
        mDataSetObservable.informInvalidated();
    }
}
